package com.jinjiafeng.enjoyjoke;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.jinjiafeng.baselibrary.base.BaseActivity;
import com.jinjiafeng.baselibrary.inject.BindView;
import com.jinjiafeng.baselibrary.widget.recycleview.BaseMultiSupport;
import com.jinjiafeng.baselibrary.widget.recycleview.OnItemClickListener;

import java.util.ArrayList;

/**
 * @author jjf
 */
public class RecycleViewActivity extends BaseActivity {
    @BindView(R.id.recleView)
    RecyclerView mRecyclerView;
    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_recycle_view);
    }

    @Override
    protected void initTitle() {

    }

    @Override
    protected void initView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        final ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            strings.add("我是第" + i + "条数据");
        }
        final MyAdapter myAdapter= new MyAdapter(strings, new BaseMultiSupport<String>() {
            @Override
            public int getLayoutId(String s) {
                if("我是第10条数据".equals(s) || "我是第15条数据".equals(s)||"我是第20条数据".equals(s)){
                    return R.layout.item_recycle;
                }else{
                    return R.layout.item_recycle2;
                }
            }
        });
        mRecyclerView.setAdapter(myAdapter);
        myAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Toast.makeText(mContext,strings.get(position), Toast
                        .LENGTH_SHORT).show();
                myAdapter.remove(position);
            }
        });

        final ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.drawable.timg);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myAdapter.removeHeaderView(v);
            }
        });
        final ImageView imageView2 = new ImageView(this);
        imageView2.setImageResource(R.drawable.ic_launcher_background);
        imageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myAdapter.removeFooterView(v);
            }
        });

        myAdapter.addHeaderView(imageView);
        myAdapter.addFooterView(imageView2);
    }

    @Override
    protected void initData() {

    }
}
